package com.manage.dao.impl;

import com.manage.dao.RoomDao;
import com.manage.pojo.Room;
import com.manage.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class RoomDaoImpl implements RoomDao {

        @Override
        public List<Room> findAll() throws SQLException {
            QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
            List<Room> query = qr.query("select * from room", new BeanListHandler<Room>(Room.class));
            return query;
        }

    @Override
    public int deleteroomByHid(int hid) throws SQLException{
        QueryRunner qr=new QueryRunner();


            String sql="DELETE FROM room WHERE hid=?";
            int update = qr.update(JDBCUtils.getConn(), sql, hid);

            return update;

    }

    @Override
    public int deleteroomByBid(int bid) throws SQLException{
        QueryRunner qr=new QueryRunner();


        String sql="DELETE FROM room WHERE bid=?";
        int update = qr.update(JDBCUtils.getConn(), sql, bid);

        return update;
    }

}
